package com.melodyframe.common.tools.javax;

import java.util.ArrayList;
import java.util.Comparator;

public class SortedList<E> extends ArrayList<E> {
	private static final long	serialVersionUID	= 6446309690654348563L;

	private Comparator<E>		comparator;

	public SortedList(Comparator<E> comparator) {
		this.comparator = comparator;
	}

	@Override
	public boolean add(E e) {
		for (int i = 0; i < this.size(); i++) {
			if (comparator.compare(e, this.get(i)) < 0) {
				this.add(i, e);
				return true;
			}
		}
		return super.add(e);
	}

}
